<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<html>
<head>
<%@include file="_header.jsp"%>
<title>修改网站角色 - 管理员管理 - H-ui.admin v3.1</title>
<meta name="keywords"
	content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
<meta name="description"
	content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
	<article class="page-container">
		<form action="" method="post" class="form form-horizontal"
			id="form-admin-role-add">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span
					class="c-red">*</span>角色名称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder=""
						id="roleName" name="name">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">备注：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="description"
						name="description">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">网站角色：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<c:forEach items="${privilegeList}" var="first" varStatus="firstvar">
					<dl class="permission-list">
						<dt>
							<label> <input type="checkbox" value="${first.id}" name="privileges" id="privilege-id-${firstvar.index}">${first.name}</label>
						</dt>
						<dd>
						   <c:forEach items="${first.subList}" var="second" varStatus="secondvar">
							<dl class="cl permission-list2">
								<dt>
									<label class=""> <input type="checkbox" value="${second.id}"
										name="privileges" id="privilege-id-${firstvar.index}-${secondvar.index}">
										${second.name}
									</label>
								</dt>
								<dd>
								  	 <c:forEach items="${second.subList}" var="third" varStatus="thirdvar">
									 <label class=""> <input type="checkbox" value="${third.id}"
										name="privileges" id="privilege-id-${firstvar.index}-${secondvar.index}-${thirdvar.index}">
										${third.name}
									</label> 
									</c:forEach>
								</dd>
							</dl>
							</c:forEach>
						</dd>
					</dl>
					</c:forEach>
					
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<button type="submit" class="btn btn-success radius"
						id="admin-role-save" name="admin-role-save">
						<i class="icon-ok"></i> 确定
					</button>
				</div>
			</div>
		</form>
	</article>

	<%@ include file="_footer.jsp"%>
	<!--请在下方写此页面业务相关的脚本-->
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/lib/jquery.validation/1.14.0/validate-methods.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/lib/jquery.validation/1.14.0/messages_zh.js"></script>
	<script type="text/javascript">
	$(function() {
	    $(".permission-list dt input:checkbox").click(function() {
	        $(this).closest("dl").find("dd input:checkbox").prop("checked", $(this).prop("checked"));
	    });
	    $(".permission-list2 dd input:checkbox").click(function() {
	        var l = $(this).parent().parent().find("input:checked").length;
	        var l2 = $(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
	        if ($(this).prop("checked")) {
	            $(this).closest("dl").find("dt input:checkbox").prop("checked", true);
	            $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", true);
	        } else {
	            if (l == 0) {
	                $(this).closest("dl").find("dt input:checkbox").prop("checked", false);
	            }
	            if (l2 == 0) {
	                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", false);
	            }
	        }
	    });

	    $("#form-admin-role-add").validate({
	        rules: {
	            roleName: {
	                required: true,
	            },
	        },
	        onkeyup: false,
	        focusCleanup: true,
	        success: "valid",
	        submitHandler: function(form) {
	            $(form).ajaxSubmit({
	                url: '${pageContext.request.contextPath}/sys/role/add',
	                datatype: "json",
	                success: function(data) {
	                    if (data.success) {
	                        //刷新父页面--刷新列表数据
	                        window.parent.location.reload();
	                        //关闭新增对话框-layer
	                        layer_close();
	                    } else {
	                        layer.msg(data.errorMsg, {
	                            icon: 1,
	                            time: 1000
	                        });
	                    }
	                },
	                error: function(data) {

	                    layer.msg('error!', {
	                        icon: 1,
	                        time: 1000
	                    });
	                    //关闭新增对话框-layer
	                    layer_close();
	                }
	            });
	        }
	    });
	});		
	</script>
	<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>